<template>
  <!-- 大模板 -->
  <el-drawer title="选择模板" :visible="value" custom-class="drawer-box" size="500px" @open="onOpen" @close="onClose" :append-to-body="true">
    <br />
    <el-form :inline="true" @submit.native.prevent="getData(-1)" style="padding-left:15px;">
      <el-form-item>
        <el-input v-model="form.name" placeholder="名称"></el-input>
      </el-form-item>
      <!-- <el-form-item>
        <el-select v-model="form.refType" @change="onRefType" clearable >
          <el-option :value="0" label="通用"></el-option>
          <el-option :value="1" label="个人"></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" circle icon="el-icon-search" native-type="submit"></el-button>
      </el-form-item>
    </el-form>
    <table class="table-box">
      <thead>
        <tr>
          <th>名称</th>
          <th>类型</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(item,index) in tableList" :key="index" @click="onDetail(item)">
          <td>{{item.templateName}}</td>
          <td>{{item.refType==0?"通用":"个人"}}</td>
        </tr>
      </tbody>
    </table>
    <div v-if="tableList.length == 0" style="color:#999;padding:10px 0;text-align:center;">
      <i class="iconfont iconwushuju" style="font-size:40px;"></i>
      <div>暂无数据</div>
    </div>
    <br />
    <pager v-model="pager" @change-pagenum="getData"></pager>
  </el-drawer>
</template>
<script>
export default {
  props: ["value", "deptId", "doctorId"],
  components: {},
  data() {
    return {
      form: {
        name: "",
        userId: "",
        deptId: ""
      },
      tableList: [],
      pager: { pageSize: 10, pageNum: 1, total: 0 }
    };
  },
  mounted() {
    const th = this;
  },
  methods: {
    onRefType() {
      const th = this;
      if (th.form.refType == 0) {
        th.form.refId = th.deptId;
      } else {
        th.form.refId = th.doctorId;
      }
    },
    onDetail(obj) {
      const th = this;
      let j = {
        id: obj.id
      };
      th.$api.doctorOutpatientTemplatecureid(j).then(res => {
        if (res.executed) {
          const data = res.data;
          let j = {
            // id: data.comboId, 模板不需要id
            cureRegister: data.cureRegisterVO,
            t0: null,
            t1: null,
            t2: data.medicalAdviceVOS,
            t3: data.checkupVOS,
            t4: data.checkAssistVOS,
            t5: data.materialFeeVOS,
            t6: data.othersFeeVOS,
            
          };
          //开启提示
          th.$store.commit("Set_templateSaveAuto", j);
          th.$store.commit("Set_templateData", j);
          th.$message.success("加入成功");
          th.onClose();
        }
      });
    },
    getData(type) {
      const th = this;
      if (type == -1) {
        th.pager.pageNum = 1;
        th.pager.total = 0;
      }
      let j = {};
      Object.assign(j, th.form, th.pager);
      th.$api.newdoctorOutpatientTemplate(j).then(res => {
        if (res.executed) {
          th.tableList = res.dataBody.list;
          th.pager.total = res.dataBody.total;
        }
      });
    },
    onOpen() {
      const th = this;
      th.form.deptId = th.deptId;
      th.form.userId = th.doctorId;
      th.getData(-1);
    },
    onClose() {
      const th = this;
      th.$emit("input", false);
    }
  }
};
</script>
<style lang="scss" scoped>
</style>